﻿// ==PREPROCESSOR==
// @name "DarkOne Control Panel"
// @version "3.1"
// @author "T.P Wang and tedGo"
// @import "%fb2k_path%themes\DarkOne_v4.0\Others\WSH Scripts\DO 4.0 Global Script.js"
// @import "%fb2k_path%themes\DarkOne_v4.0\Others\WSH Scripts\DO 4.0 Global Button Script.js"
// ==/PREPROCESSOR==

window.MinWidth = 280;
var play_pause = window.GetProperty("Play & Pause Color Buttons", true);
// ----- CREATE BUTTONS -----
var a = {normal: imgPath + "AddOnAlone.png", hover: imgPath + "AddOnAloneMH.png"};
var b = {normal: imgPath + "AddOnLeft.png", hover: imgPath + "AddOnLeftMH.png"};
var c = {normal: imgPath + "AddOnMiddle.png", hover: imgPath + "AddOnMiddleMH.png"};
var d = {normal: imgPath + "AddOnRight.png", hover: imgPath + "AddOnRightMH.png"};
var e = {normal: imgPath + "Stop2.png", hover: imgPath + "Stop2MH.png"};
var f = {normal: imgPath + "Stop.png", hover: imgPath + "StopMH.png"};
var g = {normal: imgPath + "Previous2.png", hover: imgPath + "Previous2MH.png"};
var h = {normal: imgPath + "Previous.png", hover: imgPath + "PreviousMH.png"};
var i = {normal: imgPath + "Play.png", hover: imgPath + "PlayMH.png"};
var j = {normal: imgPath + "Pause.png", hover: imgPath + "PauseMH.png"};
var k = {normal: imgPath + "PlayPause.png", hover: imgPath + "PlayPauseMH.png"};
var l = {normal: imgPath + "Next2.png", hover: imgPath + "Next2MH.png"};
var m = {normal: imgPath + "Next.png", hover: imgPath + "NextMH.png"};
var n = {normal: imgPath + "Random2.png", hover: imgPath + "Random2MH.png"};
var o = {normal: imgPath + "Random.png", hover: imgPath + "RandomMH.png"};

Buttons.opencd = new Button(1, 22, 60, 14, a, function(){fb.RunMainMenuCommand("File/Open Audio CD...")});
Buttons.open = new Button(ww / 2 - 112, 22, 58, 14, b, function(){fb.RunMainMenuCommand("File/Open...")});
Buttons.addfiles = new Button(ww / 2 - 54, 22, 55, 14, c, function(){fb.AddFiles()});
Buttons.adddirectory = new Button(ww / 2 + 1, 22, 55, 14, c, function(){fb.AddDirectory()});
Buttons.addloc = new Button(ww / 2 + 56, 22, 57, 14, d, function(){fb.RunMainMenuCommand("File/Add location...")}, "Add Location...");
Buttons.clear = new Button(ww - 60, 22, 60, 14, a, function(){fb.RunMainMenuCommand("Edit/Clear")});
Buttons.stop = new Button(1, 50, 60, 30, e, function(){fb.Stop(); fb.RunMainMenuCommand("ELPlaylist/Redraw")});
Buttons.prev = new Button(ww / 2 - 112, 50, 58, 30, g, function(){fb.Prev()});
Buttons.play = new Button(ww / 2 - 54, 50, 55, 30, i, function(){fb.Play()});
Buttons.pause = new Button(ww / 2 + 1, 50, 55, 30, j, function(){fb.Pause()});
Buttons.next = new Button(ww / 2 + 56, 50, 57, 30, l, function(){fb.Next()});
Buttons.random = new Button(ww - 60, 50, 60, 30, n, function(){fb.Random()});
Buttons.playorpause = new Button(ww / 2 - 27, 50, 55, 30, k, function(){fb.PlayOrPause()});

// ----- DRAW -----
var x1 = x2 = x3 = x4 = x5 = 0;

function on_paint(gr) {

	if (!window.IsTransparent) {
		gr.FillSolidRect(0, 0, ww, wh, ui_backcol);
		gr.FillGradRect(0, 0, ww, wh, 90, RGBA(151, 180, 202, 128), 0);
	}

	buttonsDraw(gr);

	gr.GdiDrawText("OPEN CD", btn_font, ui_btntxtcol, x1, 10, 54, 10, 33);
	gr.GdiDrawText("OPEN FILES", btn_font, ui_btntxtcol, x2, 10, 54, 10, 33);
	gr.GdiDrawText("ADD FILES", btn_font, ui_btntxtcol, x3, 10, 54, 10, 33);
	gr.GdiDrawText("ADD FOLDER", btn_font, ui_btntxtcol, x4, 10, 54, 10, 33);
	gr.GdiDrawText("ADD LOC.", btn_font, ui_btntxtcol, x5, 10, 54, 10, 33);

	if (ww > 346) {
        gr.GdiDrawText("CLEAR LIST", btn_font, ui_btntxtcol, ww - 57, 10, 54, 10, 33);
    
    if (play_pause && fb.IsPlaying) {    
        gr.SetSmoothingMode(4);  // AntiAlias for graphics
        gr.FillPolygon(RGBA(55, 195, 55, 230),1 ,[ww / 2 - 32, 60, ww / 2 - 23, 64, ww / 2 - 32, 68]);  //play
        gr.FillPolygon(RGBA(55, 205, 55, 230),1 ,[ww / 2 - 32, 61, ww / 2 - 23, 65, ww / 2 - 32, 69]);  //play
    }
    
    if (play_pause && fb.IsPaused) {
        gr.SetSmoothingMode(3);  // AntiAlias for graphics.
        gr.FillSolidRect(ww / 2 + 24, 61, 3, 8, RGBA(245, 55, 0, 230)); //pause
        gr.FillSolidRect(ww / 2 + 29, 61, 3, 8, RGBA(245, 55, 0, 230)); //pause
    }
  
  } else {  //PlayOrPause
    if (play_pause && (fb.IsPlaying || fb.IsPaused)) {
    var color = fb.IsPaused ? RGBA(128, 192, 255, 230) : RGBA(191, 228, 255, 230);
        gr.FillPolygon(color,1 ,[ww / 2 - 6, 60, ww / 2 - 1, 64, ww / 2 - 6, 68]);
        gr.FillPolygon(color,1 ,[ww / 2 - 6, 61, ww / 2 - 1, 65, ww / 2 - 6, 69]);
        gr.FillSolidRect(ww / 2 + 1, 61, 2, 8, color);
        gr.FillSolidRect(ww / 2 + 4, 61, 2, 8, color);
    }
  
  }

}

// ----- EVENTS -----
function on_size() {
	ww = window.Width;
	wh = window.Height;

	if (ww > 346) {
		x1 = 4;
		x2 = ww / 2 - 108;
		x3 = ww / 2 - 54;
		x4 = ww / 2 + 1;
		x5 = ww / 2 + 56;
	} else {
		x1 = (ww > 290) ? 3 : ww / 2 - 137;
		x2 = ww / 2 - 82;
		x3 = ww / 2 - 27;
		x4 = ww / 2 + 28;
		x5 = (ww > 290) ? ww - 57 : ww / 2 + 83;
	}

	if(ww > 346) {
		Buttons.opencd.changePos(1, 22, 60, 14);
		Buttons.opencd.alterImage(a);
		Buttons.open.changePos(ww / 2 - 112, 22, 58, 14);
		Buttons.open.alterImage(b);
		Buttons.addfiles.changePos(x3, 22, 55, 14);
		Buttons.addloc.changePos(x5, 22, 57, 14);
		Buttons.addloc.alterImage(d);
		Buttons.adddirectory.changePos(ww / 2 + 1, 22, 55, 14);
		Buttons.adddirectory.alterImage(c);
		Buttons.stop.changePos(1, 50, 60, 30);
		Buttons.stop.alterImage(e);
		Buttons.prev.changePos(ww / 2 - 112, 50, 58, 30);
		Buttons.prev.alterImage(g);
		Buttons.next.changePos(x5, 50, 57, 30);
		Buttons.next.alterImage(l);
		Buttons.random.changePos(ww - 60, 50, 60, 30);
		Buttons.random.alterImage(n);
		Buttons.play.changePos(x3, 50, 55, 30);
		Buttons.pause.changePos(x4, 50, 55, 30);
		Buttons.clear.changePos(ww - 60, 22, 60, 14);
		Buttons.play.changeState(ButtonStates.normal);
		Buttons.pause.changeState(ButtonStates.normal);
		Buttons.clear.changeState(ButtonStates.normal);
		Buttons.playorpause.changeState(ButtonStates.hide);
	} else {
		if (ww > 290) {
			Buttons.opencd.changePos(0, 22, 60, 14);
			Buttons.opencd.alterImage(a);
			Buttons.open.changePos(ww / 2 - 85, 22, 58, 14);
			Buttons.open.alterImage(b);
			Buttons.addfiles.changePos(x3, 22, 55, 14);
			Buttons.addloc.changePos(ww - 60, 22, 60, 14);
			Buttons.addloc.alterImage(a);
			Buttons.adddirectory.changePos(x4, 22, 57, 14);
			Buttons.adddirectory.alterImage(d);
			Buttons.stop.changePos(0, 50, 60, 30);
			Buttons.stop.alterImage(e);
			Buttons.prev.changePos(ww / 2 - 85, 50, 58, 30);
			Buttons.prev.alterImage(g);
			Buttons.next.changePos(x4, 50, 57, 30);
			Buttons.next.alterImage(l);
			Buttons.random.changePos(ww - 60, 50, 60, 30);
			Buttons.random.alterImage(n);
		} else {
			Buttons.opencd.changePos(ww / 2 - 140, 22, 58, 14);
			Buttons.opencd.alterImage(b);
			Buttons.open.changePos(x2, 22, 55, 14);
			Buttons.open.alterImage(c);
			Buttons.addfiles.changePos(x3, 22, 55, 14);
			Buttons.addloc.changePos(ww / 2 + 83, 22, 57, 14);
			Buttons.addloc.alterImage(d);
			Buttons.adddirectory.changePos(x4, 22, 55, 14);
			Buttons.adddirectory.alterImage(c);
			Buttons.stop.changePos(ww / 2 - 140, 50, 58, 30);
			Buttons.stop.alterImage(f);
			Buttons.prev.changePos(x2, 50, 55, 30);
			Buttons.prev.alterImage(h);
			Buttons.next.changePos(x4, 50, 55, 30);
			Buttons.next.alterImage(m);
			Buttons.random.changePos(ww / 2 + 83, 50, 57, 30);
			Buttons.random.alterImage(o);
		}
		Buttons.playorpause.changePos(x3, 50, 55, 30);
		Buttons.play.changeState(ButtonStates.hide);
		Buttons.pause.changeState(ButtonStates.hide);
		Buttons.clear.changeState(ButtonStates.hide);
		Buttons.playorpause.changeState(ButtonStates.normal);
	}
}